package com.ruoyi.notes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.notes.domain.IndexNotes;
import com.ruoyi.notes.service.IIndexNotesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备忘录Controller
 * 
 * @author yx
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/notes/notes")
public class IndexNotesController extends BaseController
{
    @Autowired
    private IIndexNotesService indexNotesService;

    /**
     * 查询备忘录列表
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndexNotes indexNotes)
    {
        startPage();
        List<IndexNotes> list = indexNotesService.selectIndexNotesList(indexNotes);
        return getDataTable(list);
    }

    /**
     * 导出备忘录列表
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:export')")
    @Log(title = "备忘录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndexNotes indexNotes)
    {
        List<IndexNotes> list = indexNotesService.selectIndexNotesList(indexNotes);
        ExcelUtil<IndexNotes> util = new ExcelUtil<IndexNotes>(IndexNotes.class);
        util.exportExcel(response, list, "备忘录数据");
    }

    /**
     * 获取备忘录详细信息
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:query')")
    @GetMapping(value = "/{notesId}")
    public AjaxResult getInfo(@PathVariable("notesId") String notesId)
    {
        return success(indexNotesService.selectIndexNotesByNotesId(notesId));
    }

    /**
     * 新增备忘录
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:add')")
    @Log(title = "备忘录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndexNotes indexNotes)
    {
        return toAjax(indexNotesService.insertIndexNotes(indexNotes));
    }

    /**
     * 修改备忘录
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:edit')")
    @Log(title = "备忘录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndexNotes indexNotes)
    {
        return toAjax(indexNotesService.updateIndexNotes(indexNotes));
    }

    /**
     * 删除备忘录
     */
    @PreAuthorize("@ss.hasPermi('notes:notes:remove')")
    @Log(title = "备忘录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notesIds}")
    public AjaxResult remove(@PathVariable String[] notesIds)
    {
        return toAjax(indexNotesService.deleteIndexNotesByNotesIds(notesIds));
    }
}
